package com.changgou.service.impl;

import com.alibaba.fescar.spring.annotation.GlobalTransactional;
import com.changgou.dao.LogInfoMapper;
import com.changgou.feign.OrderInfoFeign;
import com.changgou.feign.UserInfoFeign;
import com.changgou.pojo.LogInfo;
import com.changgou.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: hushengjin
 */
@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private LogInfoMapper logInfoMapper;
    @Autowired
    private OrderInfoFeign orderInfoFeign;
    @Autowired
    private UserInfoFeign userInfoFeign;

    /**
     * 下单
     *
     * @param username
     * @param count
     * @param id
     */
    //@Transactional(rollbackFor = Exception.class)
    @GlobalTransactional(name = "add")
    @Override
    public void add(String username, int count, int id) {
        //添加订单日志
        LogInfo logInfo = new LogInfo();
        logInfo.setContent("添加订单数据" + new Date());
        logInfo.setCreatetime(new Date());
        int i = logInfoMapper.insertSelective(logInfo);
        System.out.println("受影响的行数:" + i);
        //添加订单
        orderInfoFeign.add(username, count, id);
        //用户金额递减
        userInfoFeign.decrMoney(username, 10);
    }
}
